1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| #include <iostream> #include <cstdio> #include <cstring>
#define lson root << 1 #define rson root << 1 | 1
using namespace std;
typedef long long LL;
const int MAXN = 5e05 + 10;
int limit, N, k, d;
LL subsum[MAXN << 2]= {0}; LL lmax[MAXN << 2]= {0}, rmax[MAXN << 2]= {0}; LL sumax[MAXN << 2]= {0}; void maintain (int root) { subsum[root] = subsum[lson] + subsum[rson]; lmax[root] = max (lmax[lson], subsum[lson] + lmax[rson]); rmax[root] = max (rmax[rson], rmax[lson] + subsum[rson]); sumax[root] = max (sumax[lson], max (sumax[rson], rmax[lson] + lmax[rson])); } void build (int root, int left, int right) { if (left == right) { subsum[root] = lmax[root] = rmax[root] = sumax[root] = - k; return ; } int mid = (left + right) >> 1; build (lson, left, mid), build (rson, mid + 1, right); maintain (root); } void modify (int root, int left, int right, int posi, int delta) { if (left == right) { subsum[root] += delta; lmax[root] += delta, rmax[root] += delta; sumax[root] += delta; return ; } int mid = (left + right) >> 1; posi <= mid ? modify (lson, left, mid, posi, delta) : modify (rson, mid + 1, right, posi, delta); maintain (root); }
int getnum () { int num = 0; char ch = getchar (); bool isneg = false;
while (! isdigit (ch)) { if (ch == '-') isneg = true; ch = getchar (); } while (isdigit (ch)) num = (num << 3) + (num << 1) + ch - '0', ch = getchar ();
return isneg ? - num : num; }
int main () { limit = getnum (), N = getnum (), k = getnum (), d = getnum (); build (1, 1, limit); for (int i = 1; i <= N; i ++) { int posi = getnum (), delta = getnum (); modify (1, 1, limit, posi, delta); LL deal = sumax[1]; deal <= 1ll * k * d ? puts ("TAK") : puts ("NIE"); }
return 0; }
|